#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
using namespace std;

int maxSumDivThree(vector<int>& nums) {
    int sum = 0;
    int x1 = 0X3F3F3F3F, x2 = 0X3F3F3F3F;
    int y1 = 0X3F3F3F3F, y2 = 0X3F3F3F3F;

    for (auto e : nums)
        sum += e;

    for (auto e : nums)
    {
        if (e % 3 == 1)
        {
            if (e < x1)
            {
                x2 = x1;
                x1 = e;
            }
            else if (x1 <= e && e <= x2)
            {
                x2 = e;
            }
        }
        else if (e % 3 == 2)
        {
            if (e < y1)
            {
                y2 = y1;
                y1 = e;
            }
            else if (y1 <= e && e <= y2)
            {
                y2 = e;
            }
        }
    }

    if (sum % 3 == 1)
    {
        sum = max(sum - x1, sum - y1 - y2);
    }
    else if (sum % 3 == 2)
    {
        sum = max(sum - y1, sum - x1 - x2);
    }

    return sum;
}

int main()
{

    return 0;
}